package s;

import org.apache.lucene.index.IndexReader;
import org.apache.lucene.analysis.Analyzer
import org.apache.lucene.analysis.standard.StandardAnalyzer
import org.apache.lucene.document.Document
import org.apache.lucene.document.Field
import org.apache.lucene.document.TextField
import org.apache.lucene.index.AtomicReader
import org.apache.lucene.index.DirectoryReader
import org.apache.lucene.index.IndexWriter
import org.apache.lucene.index.IndexWriterConfig
import org.apache.lucene.store.Directory
import org.apache.lucene.store.RAMDirectory
import org.apache.lucene.util.Version;

class IndexG {
	private IndexWriter iwriter;
	Directory dir = new RAMDirectory();

	IndexG (){
		Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_42);
		IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_CURRENT, analyzer);
		iwriter = new IndexWriter(dir, config);
	}

	AtomicReader addStringToIndex (String s){
		Document doc = new Document();
		//String text = "This is the text to be indexed.";
		doc.add(new Field(Constants.FIELD_CONTENTS, s, TextField.TYPE_STORED));
		iwriter.addDocument(doc);
		//iwriter.close();
		//return new IndexReader(iwriter);
		print ("in indx g " + s);
		iwriter.close();
		//print (" iwrtiet " + iwriter.numRamDocs())
		DirectoryReader dr= DirectoryReader.open(dir);
		AtomicReader ar = dr.leaves().get(0).reader();
		return ar
	}
}


